package ModelLayer;

import java.util.ArrayList;
import java.util.Iterator;

public class Customer {
	
	
	private int customerId;
	private String name;
	private String address;
	private String zipCode;
	private int phoneNo;
	private String email;
	private ArrayList<SalesOrder> saleOrders;
	
	public Customer(int customerId, String name,
			String address, String zipCode, String email, int phoneNo) 
	{
		
		this.customerId = customerId;
		this.name = name;
		this.address = address;
		this.zipCode = zipCode;
		this.phoneNo = phoneNo;
		this.email = email;
		saleOrders = new ArrayList<SalesOrder>();
	}
	
	public Customer(){
		
	}
	
	
	public int getCustomerId() {
		return customerId;
	}
	public void setCustomerId(int customerId) {
		this.customerId = customerId;
	}
	
	public String getName(){
		return name;
	}
	
	public void setName(String name){
		this.name = name;
	}
	
	
	public String getAddress() {
		return address;
	}
	public void setAddress(String address) {
		this.address = address;
	}
	public String getZipCode() {
		return zipCode;
	}
	public void setZipCode(String zipCode) {
		this.zipCode = zipCode;
	}	
	public int getPhoneNo() {
		return phoneNo;
	}
	public void setPhoneNo(int phoneNo) {
		this.phoneNo = phoneNo;
	}
	
	public String getEmail(){
		return email;
	}
	
	public void setEmail(String email){
		this.email= email;
	}
	
	
	public void addSale(SalesOrder saleOrder){
		saleOrders.add(saleOrder);
	}
	
	public void removeSale(SalesOrder saleOrder) {
		saleOrders.remove(saleOrder);
	}
	
	public SalesOrder getSalesOrder(int id) throws Exceptions {  
		SalesOrder saleOrder = null;
		        boolean found = false;
		       Iterator<SalesOrder> it = saleOrders.iterator();
		        while(it.hasNext() && !found)
		        {
		        	SalesOrder orders = it.next();
		            if(orders.getSalesOrderId() == id)
		            {
		            	saleOrder = orders;
		                found = true;
		            } 
		        }
		        if(!found) throw new Exceptions("Order was not found");
		        return saleOrder;
		 }
	
	public void setSalesOrders(ArrayList<SalesOrder> saleOrders){
		this.saleOrders= saleOrders;
	}
	
	public void print(){
		System.out.println("Customer Id: " + customerId);
		System.out.println("Name: " + name);
		System.out.println("Address: " + address);
		System.out.println("ZipCode: " + zipCode);
		System.out.println("phoneNo: " + phoneNo);
		System.out.println("e-mail: " + email);
		
	}

}
	